package com.jdew.thkj.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jdew.thkj.R;

import java.util.List;


/**
 * Created by yangyang on 2017/9/22.
 */

public class SmartRefreshAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<String> list;
    private Context context;
    protected LayoutInflater mInflater;

    public SmartRefreshAdapter(Context context, List<String> list) {
        mInflater = LayoutInflater.from(context);
        this.context = context;
        this.list = list;
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.smart_list_item, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder myviewHolder = (ViewHolder) holder;
        myviewHolder.BindView(holder, position);
        myviewHolder.itemView.setTag(position);

    }

    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView title;

        ViewHolder(View view) {
            super(view);
            title = (TextView) view.findViewById(R.id.title);
        }

        public void BindView(RecyclerView.ViewHolder holder, final int position) {
            ((ViewHolder) holder).title.setText(list.get(position));
        }
    }
}
